﻿document.observe("dom:loaded", loadCart);
//strPathLink_All = "http://localhost:50606/";
var paramUpdateCart = { "stpe": "updateCartItem", "proID": 0, "tpPro": 0, "quantity": 0, "subID": 0, "optionID": 0, "strOption": "", "optionName": "" };
var paramRemoveCart = { "stpe": "removeCartItem", "proID": 0, "subID": 0 };
var row = 3; //num row popup deal option item
var objTaxCode = null;
var paramAcceptTax = { 'stpe': 'setInfoTax', 'name': '', 'address': '', 'codetax': '', 'isTaxCode': false };
var paramCheckUsePay = { 'stpe': 'setInfoUsePay', 'isCheckPay': 0, 'sourceWeb': 0 };
function loadCart() {
    loadEventCart();
    /*22.10.2012*/
    if (isTouchDevice()) {
        var agent = window.navigator.userAgent,
        start = agent.indexOf('OS ');
        if ((agent.indexOf('iPhone') > -1 || agent.indexOf('iPad') > -1) && start > -1) {
            $j('.cc-select').css({ "display": "none" });
            $j('.ddl_device_cart').change(changeTblQuantity_Device);
            $j('.ddl_device_cart').css({"display":"block"});
        }
    }
    
};
/*function: goi su kien page cart*/
function loadEventCart() {
    if ($('spnNextPhoto') != null) { $('spnNextPhoto').observe('click', showEffect); }
    try {
        $('divCartContent').observe('click', changeTblQuantity);
        $('divCartContent').select('.cc-typepro').invoke('observe', 'click', showPopUpCart);
        $('divCartContent').select('.cc-pro-remove').invoke('observe', 'click', removeCartItem);
        $('divCartContent').select('.cc-check').invoke('observe', 'click', checkAccountMoney);
        if ($('btnEditTax') != null) $('btnEditTax').observe('click', showPopUpTax);
    } catch (ex) { };
};
/*function: check tai khoan khuyen mai */
function checkAccountMoney(e) {
    var ele = Event.element(e);
    if (ele.hasClassName('cc-tax')) {
        if (ele.hasClassName('cc-checked')) {
            ele.removeClassName('cc-checked');
            paramAcceptTax.isTaxCode = false;
            paramAcceptTax.name = "";
            paramAcceptTax.address = "";
            paramAcceptTax.codetax = "";
            if ($('spAjaxLoader')) {
                $j('#spAjaxLoader').css({ "height": $j('.mod-descriptions').height() + "px" });
                $('spAjaxLoader').show();
            }
            var strUrlLocation = window.location.href;
            strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
            var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
            if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
                strUrlLink = strPathLink_All + "yahoo/";
            }
            if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
                utils.call(strUrlLink + "nhommuav4/HandlerRq.aspx", paramAcceptTax, "POST", "resultRemoveTax", "resultRemoveTax");
            }
            else {
                utils.call(strUrlLink + strStateNM + "/nhommuav4/HandlerRq.aspx", paramAcceptTax, "POST", "resultRemoveTax", "resultRemoveTax");
                //utils.call("http://localhost:50606/NhomMuaV4/HandlerRq.aspx", paramAcceptTax, "POST", "resultRemoveTax", "resultRemoveTax");
            }
        }
        else {
            ele.addClassName('cc-checked');
            if (objTaxCode != null && objTaxCode.isCodeTax == true) {
                $("btnEditTax").style.display = "block";
            }
            if ($("btnEditTax") != null && $("btnEditTax").style.display == "none") {
                showPopUpTax();
            }
        }

    }
    else {
        if (ele.hasClassName('cc-checked')) {
            ele.removeClassName('cc-checked');

            paramCheckUsePay.isCheckPay = 0;
            var objAccountPrice = ele.up('.cc-subrow').down('.cc-item-price').down('span');
            var accountPrice = parseFloat(objAccountPrice.next().innerHTML);
            var objTotalPrice = ele.up('.cc-subrow').previous().down('.cc-item-price').down('span');
            var totalPrice = parseFloat(objTotalPrice.next().innerHTML);
            var subPrice = totalPrice - accountPrice;
            var totalAmount = parseFloat($("spnTotalPrice").next().innerHTML);
            if (subPrice > 0) {
                $("spnTotalPrice").innerHTML = formatMoney(totalAmount + accountPrice, "", ",", "") + "<i>đ</i>";
                $("spnTotalPrice").next().innerHTML = totalAmount + accountPrice;
                //set tong tien gio hang tren header
                $("totalMoneyHeader").innerHTML = formatMoney(totalAmount + accountPrice, "", ",", "") + "<sup>đ</sup>";
            }
            else {
                $("spnTotalPrice").innerHTML = formatMoney(totalAmount + totalPrice, "", ",", "") + "<i>đ</i>";
                $("spnTotalPrice").next().innerHTML = totalAmount + totalPrice;
                //set tong tien gio hang tren header
                $("totalMoneyHeader").innerHTML = formatMoney(totalAmount + totalPrice, "", ",", "") + "<sup>đ</sup>";
            }
            //set tong tien gio hang tren header
            //$("totalMoneyHeader").innerHTML = formatMoney(totalAmount + totalPrice, "", ",", "") + "<sup>đ</sup>";
            // Edit Cung 01.08.12 -- them -
            objAccountPrice.innerHTML = "-" + formatMoney(accountPrice, "", ",", "") + "<i>đ</i>";
        }
        else {//checked
            ele.addClassName('cc-checked');
            paramCheckUsePay.isCheckPay = 1;
            var objAccountPrice = ele.up('.cc-subrow').down('.cc-item-price').down('span');
            var accountPrice = parseFloat(objAccountPrice.next().innerHTML);
            var objTotalPrice = ele.up('.cc-subrow').previous().down('.cc-item-price').down('span');
            var totalPrice = parseFloat(objTotalPrice.next().innerHTML);
            var subPrice = totalPrice - accountPrice;
            var totalAmount = parseFloat($("spnTotalPrice").next().innerHTML);
            if (subPrice > 0) {
                $("spnTotalPrice").innerHTML = formatMoney(totalAmount - accountPrice, "", ",", "") + "<i>đ</i>";
                $("spnTotalPrice").next().innerHTML = totalAmount - accountPrice;
                // Edit Cung 01.08.12 -- them -
                //objAccountPrice.innerHTML = "-" + 0 + "<i>đ</i>";
                objAccountPrice.innerHTML = 0 + "<i>đ</i>";
                //set tong tien gio hang tren header
                $("totalMoneyHeader").innerHTML = formatMoney(totalAmount - accountPrice, "", ",", "") + "<sup>đ</sup>";
            }
            else {
                $("spnTotalPrice").innerHTML = formatMoney(totalAmount - totalPrice, "", ",", "") + "<i>đ</i>";
                $("spnTotalPrice").next().innerHTML = totalAmount - totalPrice;
                // Edit Cung 01.08.12 -- them -
                objAccountPrice.innerHTML = "-" + formatMoney(accountPrice - totalPrice, "", ",", "") + "<i>đ</i>";
                //set tong tien gio hang tren header
                $("totalMoneyHeader").innerHTML = formatMoney(totalAmount - totalPrice, "", ",", "") + "<sup>đ</sup>";
            }
            //set tong tien gio hang tren header
            //$("totalMoneyHeader").innerHTML = formatMoney(totalAmount - totalPrice, "", ",", "") + "<sup>đ</sup>";
        }
        var sourceWeb = (ele.id).split("_")[1];
        paramCheckUsePay.sourceWeb = sourceWeb;
        if ($('spAjaxLoader')) {
            $j('#spAjaxLoader').css({ "height": $j('.mod-descriptions').height() + "px" });
            $('spAjaxLoader').show();
        }
        var strUrlLocation = window.location.href;
        strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
        var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
        if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
            strUrlLink = strPathLink_All + "yahoo/";
        }
        if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
            utils.call(strUrlLink + "nhommuav4/HandlerRq.aspx", paramCheckUsePay, "POST", "resultCheckUsePay", "resultCheckUsePay");
        }
        else {
            utils.call(strUrlLink + strStateNM + "/nhommuav4/HandlerRq.aspx", paramCheckUsePay, "POST", "resultCheckUsePay", "resultCheckUsePay");
            //utils.call("http://localhost:50606/NhomMuaV4/HandlerRq.aspx", paramCheckUsePay, "POST", "resultCheckUsePay", "resultCheckUsePay");
        }
    }
};
function resultCheckUsePay() {
    if ($('spAjaxLoader')) {
        $('spAjaxLoader').hide();
    }
 };
/*function: su kien onchange dropdownlist quantity tren table*/
function changeTblQuantity(e) {
    var ele = Event.element(e);
    $('divCartContent').select('.cc-list-select').each(function(s) { if (s.style.display == "block") s.style.display = "none"; });
    if (ele.tagName == 'SPAN' || ele.tagName == 'I') ele = ele.up('div');
    if (ele.hasClassName('cc-selected')) {
        var listE = ele;
        var listEle = listE.next('.cc-list-select');
        listEle.style.display = (listEle.style.display == "none") ? "block" : "none";
        if (listEle.style.display == "block") {
            listEle.observe('click', function(s) {
                var eleS = Event.element(s);
                if (eleS.tagName.toUpperCase() == "LI") {
                    if (listE.down("span").innerHTML == eleS.innerHTML) return;
                    listE.down("span").innerHTML = eleS.innerHTML;
                    listEle.style.display = "none";
                    var objTotalPrice = listEle.up('td').next(1); //obj thanh tien
                    var strID = objTotalPrice.down('span').id.split("_");

                    var objPrice = listEle.up('td').next(0).down('em'); //don gia tien
                    var price = (typeof (objPrice) != "undefined") ? parseFloat(objPrice.innerHTML) : 0; //gia san pham
                    var quantity = parseInt(eleS.innerHTML); //so luong
                    var totalPrice = quantity * price; //tong tien
                    if (typeof (objTotalPrice) != "undefined") {
                        //gan thanh tien cua item
                        var spnTPrice = objTotalPrice.down('span', 0);
                        var oldTPrice = parseFloat(spnTPrice.next().innerHTML);
                        spnTPrice.innerHTML = formatMoney(totalPrice, "", ",", "") + "<i>đ</i>"; //tong tien
                        spnTPrice.next().innerHTML = totalPrice;

                        //gan tong so tien cua tai khoan
                        var subTotalPrice = totalPrice - oldTPrice;
                        var sourceWeb = spnTPrice.id.split("_")[2];
                        var swebTPrice = parseFloat($("spnTotalPrice_" + sourceWeb + "").next().innerHTML);
                        $("spnTotalPrice_" + sourceWeb + "").innerHTML = formatMoney(swebTPrice + subTotalPrice, "", ",", "") + "<i>đ</i>"; //tong tien
                        $("spnTotalPrice_" + sourceWeb + "").next().innerHTML = swebTPrice + subTotalPrice;

                        //tinh tong so tien can thanh toan
                        var totalPriceWeb = swebTPrice + subTotalPrice;
                        var totalNM = ($("spnTotalPrice_1") != null) ? parseFloat($("spnTotalPrice_1").next().innerHTML) : 0;
                        var totalZap = ($("spnTotalPrice_2") != null) ? parseFloat($("spnTotalPrice_2").next().innerHTML) : 0;
                        var totalKay = ($("spnTotalPrice_3") != null) ? parseFloat($("spnTotalPrice_3").next().innerHTML) : 0;
                        var accountNM = ($("spnAccount_1") != null && $("iCheck_1") != null && $("iCheck_1").hasClassName('cc-checked') == true) ? parseFloat($('spnAccount_1').next().innerHTML) : 0;
                        var accountZap = ($("spnAccount_2") != null && $("iCheck_2") != null && $("iCheck_2").hasClassName('cc-checked') == true) ? parseFloat($('spnAccount_2').next().innerHTML) : 0;
                        var accountKay = ($("spnAccount_3") != null && $("iCheck_3") != null && $("iCheck_3").hasClassName('cc-checked') == true) ? parseFloat($('spnAccount_3').next().innerHTML) : 0;
                        if ($("iCheck_" + sourceWeb) != null && $("iCheck_" + sourceWeb).hasClassName('cc-checked')) {
                            var acc = parseFloat(($("spnAccount_" + sourceWeb + "").next().innerHTML))
                            if (totalPriceWeb > acc)
                                $("spnAccount_" + sourceWeb + "").innerHTML = 0 + "<i>đ</i>";
                            else
                                $("spnAccount_" + sourceWeb + "").innerHTML = formatMoney(acc - totalPriceWeb, "", ",", "") + "<i>đ</i>";
                        }
                        totalNM = ((totalNM - accountNM) > 0) ? (totalNM - accountNM) : 0;
                        totalKay = ((totalKay - accountKay) > 0) ? (totalKay - accountKay) : 0;
                        totalZap = ((totalZap - accountZap) > 0) ? (totalZap - accountZap) : 0;
                        var total = totalNM + totalZap + totalKay;
                        $("spnTotalPrice").innerHTML = formatMoney(total, "", ",", "") + "<i>đ</i>";
                        $("spnTotalPrice").next().innerHTML = total;
                        //set tong tien gio hang tren header 
                        var totalQuantity = 0;
                        $("tblContent").select('.cc-selected').each(function(s) { totalQuantity += parseInt(s.down("span").innerHTML); });
                        $("totalMoneyHeader").innerHTML = formatMoney(total, "", ",", "") + "<sup>đ</sup>";
                        $("totalAmountHeader").innerHTML = totalQuantity;
                    }
                    paramUpdateCart.quantity = quantity;
                    paramUpdateCart.proID = strID[0];
                    paramUpdateCart.subID = strID[1];
                    paramUpdateCart.tpPro = objTotalPrice.up('tr').down('.cc-typepro').id.split("_")[2];
                    if ($('spAjaxLoader')) {
                        $j('#spAjaxLoader').css({ "height": $j('.mod-descriptions').height() + "px" });
                        $('spAjaxLoader').show();
                    }
                    var strUrlLocation = window.location.href;
                    strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
                    var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
                    if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
                        strUrlLink = strPathLink_All + "yahoo/";
                    }
                    if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
                        utils.call(strUrlLink + "nhommuav4/HandlerRq.aspx", paramUpdateCart, "POST", "resultUpdateOnTable", "resultUpdateOnTable");
                    }
                    else {
                        utils.call(strUrlLink + strStateNM + "/nhommuav4/HandlerRq.aspx", paramUpdateCart, "POST", "resultUpdateOnTable", "resultUpdateOnTable");
                        //utils.call("http://localhost:50606/NhomMuaV4/HandlerRq.aspx", paramUpdateCart, "POST", "resultUpdateOnTable", "resultUpdateOnTable");
                    }
                }
            });
        }
    }
};
function changeTblQuantity_Device() {
    var ele = this;
    var objTotalPrice = ele.up('td').next(1); //obj thanh tien
    var strID = objTotalPrice.down('span').id.split("_");
    var objPrice = ele.up('td').next(0).down('em'); //don gia tien
    var price = (typeof (objPrice) != "undefined") ? parseFloat(objPrice.innerHTML) : 0; //gia san pham
    var quantity = this.value; //so luong
    var totalPrice = quantity * price; //tong tien
    if (typeof (objTotalPrice) != "undefined") {
        //gan thanh tien cua item
        var spnTPrice = objTotalPrice.down('span', 0);
        var oldTPrice = parseFloat(spnTPrice.next().innerHTML);
        spnTPrice.innerHTML = formatMoney(totalPrice, "", ",", "") + "<i>đ</i>"; //tong tien
        spnTPrice.next().innerHTML = totalPrice;

        //gan tong so tien cua tai khoan
        var subTotalPrice = totalPrice - oldTPrice;
        var sourceWeb = spnTPrice.id.split("_")[2];
        var swebTPrice = parseFloat($("spnTotalPrice_" + sourceWeb + "").next().innerHTML);
        $("spnTotalPrice_" + sourceWeb + "").innerHTML = formatMoney(swebTPrice + subTotalPrice, "", ",", "") + "<i>đ</i>"; //tong tien
        $("spnTotalPrice_" + sourceWeb + "").next().innerHTML = swebTPrice + subTotalPrice;

        //tinh tong so tien can thanh toan
        var totalPriceWeb = swebTPrice + subTotalPrice;
        var totalNM = ($("spnTotalPrice_1") != null) ? parseFloat($("spnTotalPrice_1").next().innerHTML) : 0;
        var totalZap = ($("spnTotalPrice_2") != null) ? parseFloat($("spnTotalPrice_2").next().innerHTML) : 0;
        var totalKay = ($("spnTotalPrice_3") != null) ? parseFloat($("spnTotalPrice_3").next().innerHTML) : 0;
        var accountNM = ($("spnAccount_1") != null && $("iCheck_1") != null && $("iCheck_1").hasClassName('cc-checked') == true) ? parseFloat($('spnAccount_1').next().innerHTML) : 0;
        var accountZap = ($("spnAccount_2") != null && $("iCheck_2") != null && $("iCheck_2").hasClassName('cc-checked') == true) ? parseFloat($('spnAccount_2').next().innerHTML) : 0;
        var accountKay = ($("spnAccount_3") != null && $("iCheck_3") != null && $("iCheck_3").hasClassName('cc-checked') == true) ? parseFloat($('spnAccount_3').next().innerHTML) : 0;
        if ($("iCheck_" + sourceWeb) != null && $("iCheck_" + sourceWeb).hasClassName('cc-checked')) {
            var acc = parseFloat(($("spnAccount_" + sourceWeb + "").next().innerHTML))
            if (totalPriceWeb > acc)
                $("spnAccount_" + sourceWeb + "").innerHTML = 0 + "<i>đ</i>";
            else
                $("spnAccount_" + sourceWeb + "").innerHTML = formatMoney(acc - totalPriceWeb, "", ",", "") + "<i>đ</i>";
        }
        totalNM = ((totalNM - accountNM) > 0) ? (totalNM - accountNM) : 0;
        totalKay = ((totalKay - accountKay) > 0) ? (totalKay - accountKay) : 0;
        totalZap = ((totalZap - accountZap) > 0) ? (totalZap - accountZap) : 0;
        var total = totalNM + totalZap + totalKay;
        $("spnTotalPrice").innerHTML = formatMoney(total, "", ",", "") + "<i>đ</i>";
        $("spnTotalPrice").next().innerHTML = total;
        //set tong tien gio hang tren header 
        var totalQuantity = 0;
        $("tblContent").select('.cc-selected').each(function(s) { totalQuantity += parseInt(s.down("span").innerHTML); });
        $("totalMoneyHeader").innerHTML = formatMoney(total, "", ",", "") + "<sup>đ</sup>";
        $("totalAmountHeader").innerHTML = totalQuantity;
    }
    paramUpdateCart.quantity = quantity;
    paramUpdateCart.proID = strID[0];
    paramUpdateCart.subID = strID[1];
    paramUpdateCart.tpPro = objTotalPrice.up('tr').down('.cc-typepro').id.split("_")[2];
    if ($('spAjaxLoader')) {
        $j('#spAjaxLoader').css({ "height": $j('.mod-descriptions').height() + "px" });
        $('spAjaxLoader').show();
    }
    var strUrlLocation = window.location.href;
    strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
    var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
    if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
        strUrlLink = strPathLink_All + "yahoo/";
    }
    if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
        utils.call(strUrlLink + "nhommuav4/HandlerRq.aspx", paramUpdateCart, "POST", "resultUpdateOnTable", "resultUpdateOnTable");
    }
    else {
        utils.call(strUrlLink + strStateNM + "/nhommuav4/HandlerRq.aspx", paramUpdateCart, "POST", "resultUpdateOnTable", "resultUpdateOnTable");
        //utils.call("http://localhost:50606/NhomMuaV4/HandlerRq.aspx", paramUpdateCart, "POST", "resultUpdateOnTable", "resultUpdateOnTable");
    }
};
/*function: event click san pham show popup cap nhat*/
function showPopUpCart(e) {
    var ele = Event.element(e);
    var strID = ele.id.split("_");
    var type = strID[2];
    var proID = strID[1]
    var html = "";
    if ($('spAjaxLoader')) {
        $j('#spAjaxLoader').css({ "height": $j('.mod-descriptions').height() + "px" });
        $('spAjaxLoader').show();
    }
    var strUrlLocation = window.location.href;
    strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
    var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
    if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
        strUrlLink = strPathLink_All + "yahoo/";
    }
    if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
        utils.call(strUrlLink + "nhommuav4/HandlerRq.aspx", { "stpe": "getCartItem", "proID": proID, "tpPro": type }, "POST", "resultCartItem", "resultCartItem");
    }
    else {
        utils.call(strUrlLink + strStateNM + "/nhommuav4/HandlerRq.aspx", { "stpe": "getCartItem", "proID": proID, "tpPro": type }, "POST", "resultCartItem", "resultCartItem");
        //utils.call("http://localhost:50606/NhomMuaV4/HandlerRq.aspx", { "stpe": "getCartItem", "proID": proID, "tpPro": type }, "POST", "resultCartItem", "resultCartItem");
    }
};
/*function: show poupup */
function resultCartItem(str) {
    if ($('spAjaxLoader')) {
        $('spAjaxLoader').hide();
    }
    var lang = new langCart();
    var html = "";
    var classPopUp = "";
    if (typeof (str) != "undefined" && str != "-1") {
        try { deals = str.evalJSON(true); } catch (ex) { deals = str; }
        var type = deals.TypeProduct;
        var colorIDAct = 0;
        if (type == 1)//san pham
        {
            classPopUp = "cc-zap";
            html += "<p class='cc-pop-name'>" + deals.Name + "</p>" +
            "<p>" + deals.Content + "</p>" +
            "<div class='cc-pop-img'>" +
        	     "<img src='" + deals.Picture + "' alt='" + deals.Name + "' width='405' height='250'/>" +
            "</div>" +
            "<div class='cc-pop-order'>" +
        	    "<i class='cc-pop-line top'></i>" +
                "<span class='cc-pop-order-txt'>" + lang[0] + ":</span>" +
                "<div class='cc-select'>" +
            	    "<div class='cc-selected'><span id='spanQuantity'>" + deals.Quantity + "</span><i></i></div>" +
                    "<div class='cc-list-select' style='display:none;'>" +
                        "<ul>";
            for (var i = deals.MinSale; i <= deals.MaxSale; i++) {
                html += "<li>" + i + "</li>";
            }
            html += "</ul>" +
                    "</div>" +
                "</div>" +
                "<i class='cc-pop-line bottom'></i>" +
            "</div>  " +
            "<p class='cc-pop-btn-customize'><a id='btnUpdate_" + deals.ID + "_" + deals.SubID + "_" + type + "_" + deals.MinSale + "_" + deals.MaxSale + "' class='cc-pop-btn'><i class='cc-pop-btn-txt'></i></a></p>";
        }
        else if (type == 2)//luxury
        {
            var strSize = "";


            var strColor = "";
            var strAge = "";
            var proImage = "";
            var ColorID = 0;
            var AgeID = 0;

            var ageIDAct = 0;
            var ageNameAct = "";
            var colorIDAct = 0;

            var itemAgeID = 0;
            var itemColorID = 0;

            for (var i = 0; i < deals.listKayOption.length; i++) {
                if (deals.IdKayOption == deals.listKayOption[i].OptionID) {
                    if (deals.listKayOption[i].AgeID != 0) {
                        ageIDAct = deals.listKayOption[i].AgeID;
                        ageNameAct = deals.listKayOption[i].AgeName;
                        colorIDAct = deals.listKayOption[i].ColorID;
                    }
                    else {
                        colorIDAct = deals.listKayOption[i].ColorID;
                    }
                    proImage = deals.listKayOption[i].ProductImage;
                }
                if (deals.listKayOption[i].AgeID != 0 && deals.listKayOption[i].AgeID != AgeID) {
                    itemAgeID = deals.listKayOption[i].AgeID;
                    strAge += "<li id='age_" + deals.listKayOption[i].OptionID + "_" + deals.listKayOption[i].AgeID + "'>" + deals.listKayOption[i].AgeName + "</li>";
                }
                if (deals.listKayOption[i].ColorID != 0 && (deals.listKayOption[i].ColorID != ColorID || (AgeID != 0 && deals.listKayOption[i].AgeID != AgeID))) {
                    itemColorID = deals.listKayOption[i].ColorID;
                    ColorID = deals.listKayOption[i].ColorID;
                    strColor += "<li class='color_" + itemAgeID + "' style='display:none'><a id='aColor_" + deals.listKayOption[i].OptionID + "_" + deals.listKayOption[i].ColorID + "_" + deals.listKayOption[i].AgeID + "' title='" + deals.listKayOption[i].ColorName + "' name='" + deals.listKayOption[i].ColorName + "' class='color " + ((deals.IdKayOption == deals.listKayOption[i].OptionID) ? "active" : "") + "'><img src='" + deals.listKayOption[i].ColorImage + "' alt='" + deals.listKayOption[i].ColorName + "'/></a><span style='display:none'>" + deals.listKayOption[i].ProductImage + "</span></li>";
                }

                if (deals.listKayOption[i].SizeID != 0) {
                    var classSize = ((itemAgeID != 0) ? (itemAgeID + ((itemColorID != 0) ? ("_" + itemColorID) : "")) : itemColorID);
                    strSize += "<li class='size_" + classSize + "' style='display:none'><a class='" + ((deals.IdKayOption == deals.listKayOption[i].OptionID) ? "active" : "") + "' id='aSize_" + deals.listKayOption[i].OptionID + "_" + deals.listKayOption[i].ColorID + "_" + deals.listKayOption[i].SizeID + "' name='" + deals.listKayOption[i].SizeName + "'>" + deals.listKayOption[i].SizeName + "</a><span style='display:none'>" + deals.listKayOption[i].ProductImage + "</span></li>";
                }
                AgeID = deals.listKayOption[i].AgeID;
            }
            classPopUp = "cc-kay";
            html = "<p class='cc-pop-name'>" + deals.Name + "</p>" +
            "<div class='cc-pop-img'>" +
        	     "<img id='imgKay' src='" + ((proImage != "") ? proImage : deals.PicVoucher) + "' alt='" + deals.Name + "' width='280'/>" + //Thao 25.08
            "</div>";
            html += "<div class='cc-pop-content'>";
            if (strAge != "")//list age
            {
                html += "<div class='cc-pop-order cc-pop-age'>" +
            	    "<span class='cc-pop-order-txt'>Tuổi:</span>";
                html += "<div class='cc-select'>" +
                    "<div class='cc-selected'><span id='spanAge'>" + ageNameAct + "</span><i></i></div>" +
                    "<div class='cc-list-select' style='display:none;'>" +
                        "<ul>" + strAge + "</ul>" +
                        "</div></div>";
                html += "</div>";
            }
            if (strColor != "") {//list color
                html += "<div class='cc-pop-color'>" +
            	    "<span>" + lang[1] + ":</span>" +
                    "<ul>" + strColor + "</ul></div>";
            }
            if (strSize != "") {//list size
                html += "<div class='cc-pop-size'>" +
            	    "<span>" + lang[7] + ":</span><div id='divSize'><ul>" + strSize + "</ul></div></div>";
            }
            html += "<div class='cc-pop-order'>" +

                    "<span class='cc-pop-order-txt'>" + lang[0] + ":</span>" +
                    "<div class='cc-select'>" +
                        "<div class='cc-selected'><span id='spanQuantity'>" + deals.Quantity + "</span><i></i></div>" +
                        "<div class='cc-list-select' style='display:none;'>" +
                            "<ul>";
            for (var j = deals.MinSale; j <= deals.MaxSale; j++) {
                html += "<li>" + j + "</li>";
            }
            html += "</ul>" +
                        "</div>" +
                    "</div>" +
                    "<i class='cc-pop-line bottom'></i>" +
                "</div>" +
                "<p class='cc-pop-btn-customize'><a id='btnUpdate_" + deals.ID + "_" + deals.SubID + "_" + type + "_" + deals.MinSale + "_" + deals.MaxSale + "' class='cc-pop-btn'><i class='cc-pop-btn-txt'></i></a></p>  ";

        }
        else if (type == 3)//chon item
        {
            var len = deals.subItem.length;
            var w = len * 241;
            var quantity = 0;
            classPopUp = "cc-nhienit cc-select-option";
            html = "<p class='cc-pop-name'>" + deals.Name + "</p>" +
            "<p>" + deals.Content + "</p>" +
            "<div id='gallery_container' class='cc-pop-content cc-pop-slideshow'>" +
            "<span id='spnPre' class='cc-pop-padding cc-pop-pre'></span>" +
            "<span id='spnNext' class='cc-pop-padding cc-pop-next'></span>" +
                "<div class='thumb_container'>" +
        	    "<ul id='ulListPro' class='cc-pop-listpro' style='width:" + w + "px;'>";
            for (var i = 0; i < deals.subItem.length; i++) {
                quantity = (deals.subItem[i].Quantity > 0) ? deals.subItem[i].Quantity : 1;

                html += "<li id='item_" + deals.subItem[i].SubID + "' class='cc-pop-pro thumbnail'>";
                if (i < deals.subItem.length - 1) html += "<i class='cc-line-ver'></i>";
                html += "<div class='cc-pop-pro-img'>" +
                    	    "<img src='" + deals.subItem[i].Picture + "' alt='" + deals.subItem[i].NameColor + "' width='218' height='138'/>" +
                            "<div class='cc-pop-pro-price'><span>" + formatMoney(deals.subItem[i].PriceSale, "", ",", "") + "<i>đ</i></span><em style='display:none'>" + deals.subItem[i].PriceSale + "</em></div>" +
                        "</div>" +
                        "<p class='cc-pop-pro-color'>" + sublen(deals.subItem[i].NameColor, 32) + "</p>" +
                        "<div class='cc-pop-pro-info'>" +
                    	    "<span class='cc-pop-check " + (parseInt(deals.subItem[i].Quantity) > 0 ? "cc-pop-checked" : "") + "'></span>" +
                            "<div class='cc-pop-order'>                       " +
                                "<span class='cc-pop-order-txt'>" + lang[3] + "</span>" +
                                "<div class='cc-select'>" +
                                        "<select class='cc-pop-selectbox'>";


                for (var j = deals.MinSale; j <= deals.MaxSale; j++) {
                    html += "<option value='" + j + "' " + (quantity == j ? "selected='selected'" : "") + "  >" + j + "</option>";
                }
                html += "</select>" +

                                "</div>" +
                    	    "</div> " +
                        "</div>" +
                    "</li>";
            }
            html += "</ul>" +
            "</div>" +
            "</div>" +
            "<p class='cc-pop-btn-customize'><a id='btnUpdate_" + deals.ID + "_" + deals.SubID + "_" + type + "_" + deals.MinSale + "_" + deals.MaxSale + "' class='cc-pop-btn'><i class='cc-pop-btn-txt'></i></a><i class='cc-pop-line top'></i></p>  ";
        }
        else if (type == 4) { //giay chung nhan
            classPopUp = "cc-nhienit";
            html = "<p class='cc-pop-name'>" + deals.Name + "</p>" +
                "<p>" + new langTitlePopUp()[1] + "</p>" +
                "<div class='cc-pop-img'>" +
        	         "<img src='" + deals.PicVoucher + "' alt='" + deals.Name + "' width='405' />" + //height='479'
                "</div>" +
                "<div class='cc-pop-order'>" +
        	        "<i class='cc-pop-line top'></i>" +
                    "<span class='cc-pop-order-txt'>" + lang[0] + ":</span>" +
                    "<div class='cc-select'>" +
            	        "<div class='cc-selected'><span>" + deals.Quantity + "</span><i></i></div>" +
                        "<div class='cc-list-select' style='display:none;'>" +
                           "<ul>";
            for (var i = deals.MinSale; i <= deals.MaxSale; i++) {
                html += "<li>" + i + "</li>";
            }
            html += "</ul>" +
                        "</div>" +
                    "</div>" +
                    "<i class='cc-pop-line bottom'></i>" +
                "</div>  " +
                "<p class='cc-pop-btn-customize'><a id='btnUpdate_" + deals.ID + "_" + deals.SubID + "_" + type + "_" + deals.MinSale + "_" + deals.MaxSale + "' class='cc-pop-btn'><i class='cc-pop-btn-txt'></i></a></p>";
        }
        else if (type == 5)//voucher
        {
            classPopUp = "cc-nhienit";
            html += "<p class='cc-pop-name'>" + deals.Name + "</p>" +
            "<p>" + new langTitlePopUp()[0] + "</p>" +
            "<div class='cc-pop-img'>" +
        	     "<img src='" + deals.PicVoucher + "' alt='" + deals.Name + "' width='405' />" + //height='244'
            "</div>" +
            "<div class='cc-pop-order'>" +
        	    "<i class='cc-pop-line top'></i>" +
                "<span class='cc-pop-order-txt'>" + lang[0] + ":</span>" +
                "<div class='cc-select'>" +
            	    "<div class='cc-selected'><span>" + deals.Quantity + "</span><i></i></div>" +
                    "<div class='cc-list-select' style='display:none;'>" +
                         "<ul>";
            for (var i = deals.MinSale; i <= deals.MaxSale; i++) {
                html += "<li>" + i + "</li>";
            }
            html += "</ul>" +
                    "</div>" +
                "</div>" +
                "<i class='cc-pop-line bottom'></i>" +
            "</div>  " +
            "<p class='cc-pop-btn-customize'><a id='btnUpdate_" + deals.ID + "_" + deals.SubID + "_" + type + "_" + deals.MinSale + "_" + deals.MaxSale + "' class='cc-pop-btn'><i class='cc-pop-btn-txt'></i></a></p>";
        }
        //show popup
        var divPopUp = $("divPoupCart");
        divPopUp.className = "ccart-popup " + classPopUp;
        $("divPoupCartContent").innerHTML = html;
        $j("#dShadow").fadeIn(500,function(){
            setPopUpCenter("divPoupCart");
            $j("#divPoupCart").slideDown(500);
        });
        divPopUp.down('.ccart-pop-close').observe('click', function() {//close pop up
            $j("#divPoupCart").slideUp(500,function(){
                $j("#dShadow").fadeOut(500);
            });
        });
        try {
            divPopUp.observe('click', changeQuantity);
            divPopUp.down('.cc-pop-btn').observe('click', updateCartItem);
            divPopUp.select('.cc-pop-color').invoke('observe', 'click', checkOptionColor);
            divPopUp.select('.cc-pop-size').invoke('observe', 'click', checkOptionSize);
            divPopUp.select('.cc-pop-check').invoke('observe', 'click', checkOptionItem);
        } catch (ex) { };

        if ($("gallery_container") != null) {
            finishMoveGallery();
            [$('spnNext'), $('spnPre')].invoke('observe', 'click', clickGallery);
        }
        //set size, color
        try {
            if (ageIDAct != 0) {
                divPopUp.select(".color_" + ageIDAct + "").each(function(s) { s.show(); });
                if (colorIDAct != 0) {
                    divPopUp.select(".size_" + ageIDAct + "_" + colorIDAct + "").each(function(s) { s.show(); });
                }
                else
                    divPopUp.select(".size_" + colorIDAct + "").each(function(s) { s.show(); });
            }
            else {
                if (colorIDAct != 0) {
                    divPopUp.select(".color_" + colorIDAct + "").each(function(s) { s.addClassName('active'); });
                    divPopUp.down('.cc-pop-color').select('li').each(function(s) { s.show(); });
                    divPopUp.select(".size_" + colorIDAct + "").each(function(s) { s.show(); });
                }
                else {
                    if ($("divSize") != null) { $("divSize").select('li').each(function(s) { s.show(); }); }
                }
            }
            //Thao 25.08
            if (typeof (divPopUp.down('.cc-pop-color')) == "object" && divPopUp.down('.cc-pop-color').select('li').length <= 1) {
                divPopUp.down('.cc-pop-color').style.display = "none";
            }
            if (typeof (divPopUp.down('.cc-pop-size')) == "object" && divPopUp.down('.cc-pop-size').select('li').length <= 1) {
                divPopUp.down('.cc-pop-size').style.display = "none";
            }
        } catch (ef) { };
    }
};
//function resultCartItem(str) {
//    if ($('spAjaxLoader')) {
//        $('spAjaxLoader').hide();
//    }
//    var lang = new langCart();
//    var html = "";
//    var classPopUp = "";
//    if (typeof (str) != "undefined" && str != "-1") {
//        try { deals = str.evalJSON(true); } catch (ex) { deals = str; }
//        var type = deals.TypeProduct;
//        var colorIDAct = 0;
//        if (type == 1)//san pham
//        {
//            classPopUp = "cc-zap";
//            html += "<p class='cc-pop-name'>" + deals.Name + "</p>" +
//            "<p>" + deals.Content + "</p>" +
//            "<div class='cc-pop-img'>" +
//        	     "<img src='" + deals.Picture + "' alt='" + deals.Name + "' width='405' height='250'/>" +
//            "</div>" +
//            "<div class='cc-pop-order'>" +
//        	    "<i class='cc-pop-line top'></i>" +
//                "<span class='cc-pop-order-txt'>" + lang[0] + ":</span>" +
//                "<div class='cc-select'>" +
//            	    "<div class='cc-selected'><span id='spanQuantity'>" + deals.Quantity + "</span><i></i></div>" +
//                    "<div class='cc-list-select' style='display:none;'>" +
//                        "<ul>";
//            for (var i = deals.MinSale; i <= deals.MaxSale; i++) {
//                html += "<li>" + i + "</li>";
//            }
//            html += "</ul>" +
//                    "</div>" +
//                "</div>" +
//                "<i class='cc-pop-line bottom'></i>" +
//            "</div>  " +
//            "<p class='cc-pop-btn-customize'><a id='btnUpdate_" + deals.ID + "_" + deals.SubID + "_" + type + "_" + deals.MinSale + "_" + deals.MaxSale + "' class='cc-pop-btn'><i class='cc-pop-btn-txt'></i></a></p>";
//        }
//        else if (type == 2)//luxury
//        {
//            var strSize = "";


//            var strColor = "";
//            var strAge = "";
//            var proImage = "";
//            var ColorID = 0;
//            var AgeID = 0;

//            var ageIDAct = 0;
//            var ageNameAct = "";
//            var colorIDAct = 0;

//            var itemAgeID = 0;
//            var itemColorID = 0;

//            for (var i = 0; i < deals.listKayOption.length; i++) {
//                if (deals.IdKayOption == deals.listKayOption[i].OptionID) {
//                    if (deals.listKayOption[i].AgeID != 0) {
//                        ageIDAct = deals.listKayOption[i].AgeID;
//                        ageNameAct = deals.listKayOption[i].AgeName;
//                        colorIDAct = deals.listKayOption[i].ColorID;
//                    }
//                    else {
//                        colorIDAct = deals.listKayOption[i].ColorID;
//                    }
//                    proImage = deals.listKayOption[i].ProductImage;
//                }
//                if (deals.listKayOption[i].AgeID != 0 && deals.listKayOption[i].AgeID != AgeID) {
//                    itemAgeID = deals.listKayOption[i].AgeID;
//                    strAge += "<li id='age_" + deals.listKayOption[i].OptionID + "_" + deals.listKayOption[i].AgeID + "'>" + deals.listKayOption[i].AgeName + "</li>";
//                }
//                if (deals.listKayOption[i].ColorID != 0 && (deals.listKayOption[i].ColorID != ColorID || (AgeID != 0 && deals.listKayOption[i].AgeID != AgeID))) {
//                    itemColorID = deals.listKayOption[i].ColorID;
//                    ColorID = deals.listKayOption[i].ColorID;
//                    strColor += "<li class='color_" + itemAgeID + "' style='display:none'><a id='aColor_" + deals.listKayOption[i].OptionID + "_" + deals.listKayOption[i].ColorID + "_" + deals.listKayOption[i].AgeID + "' title='" + deals.listKayOption[i].ColorName + "' name='" + deals.listKayOption[i].ColorName + "' class='color " + ((deals.IdKayOption == deals.listKayOption[i].OptionID) ? "active" : "") + "'><img src='" + deals.listKayOption[i].ColorImage + "' alt='" + deals.listKayOption[i].ColorName + "'/></a><span style='display:none'>" + deals.listKayOption[i].ProductImage + "</span></li>";
//                }

//                if (deals.listKayOption[i].SizeID != 0) {
//                    var classSize = ((itemAgeID != 0) ? (itemAgeID + ((itemColorID != 0) ? ("_" + itemColorID) : "")) : itemColorID);
//                    strSize += "<li class='size_" + classSize + "' style='display:none'><a class='" + ((deals.IdKayOption == deals.listKayOption[i].OptionID) ? "active" : "") + "' id='aSize_" + deals.listKayOption[i].OptionID + "_" + deals.listKayOption[i].ColorID + "_" + deals.listKayOption[i].SizeID + "' name='" + deals.listKayOption[i].SizeName + "'>" + deals.listKayOption[i].SizeName + "</a><span style='display:none'>" + deals.listKayOption[i].ProductImage + "</span></li>";
//                }
//                AgeID = deals.listKayOption[i].AgeID;
//            }
//            classPopUp = "cc-kay";
//            html = "<p class='cc-pop-name'>" + deals.Name + "</p>" +
//            "<div class='cc-pop-img'>" +
//        	     "<img id='imgKay' src='" + ((proImage != "") ? proImage : deals.PicVoucher) + "' alt='" + deals.Name + "' width='280'/>" + //Thao 25.08
//            "</div>";
//            html += "<div class='cc-pop-content'>";
//            if (strAge != "")//list age
//            {
//                html += "<div class='cc-pop-order cc-pop-age'>" +
//            	    "<span class='cc-pop-order-txt'>Tuổi:</span>";
//                html += "<div class='cc-select'>" +
//                    "<div class='cc-selected'><span id='spanAge'>" + ageNameAct + "</span><i></i></div>" +
//                    "<div class='cc-list-select' style='display:none;'>" +
//                        "<ul>" + strAge + "</ul>" +
//                        "</div></div>";
//                html += "</div>";
//            }
//            if (strColor != "") {//list color
//                html += "<div class='cc-pop-color'>" +
//            	    "<span>" + lang[1] + ":</span>" +
//                    "<ul>" + strColor + "</ul></div>";
//            }
//            if (strSize != "") {//list size
//                html += "<div class='cc-pop-size'>" +
//            	    "<span>" + lang[7] + ":</span><div id='divSize'><ul>" + strSize + "</ul></div></div>";
//            }
//            html += "<div class='cc-pop-order'>" +

//                    "<span class='cc-pop-order-txt'>" + lang[0] + ":</span>" +
//                    "<div class='cc-select'>" +
//                        "<div class='cc-selected'><span id='spanQuantity'>" + deals.Quantity + "</span><i></i></div>" +
//                        "<div class='cc-list-select' style='display:none;'>" +
//                            "<ul>";
//            for (var j = deals.MinSale; j <= deals.MaxSale; j++) {
//                html += "<li>" + j + "</li>";
//            }
//            html += "</ul>" +
//                        "</div>" +
//                    "</div>" +
//                    "<i class='cc-pop-line bottom'></i>" +
//                "</div>" +
//                "<p class='cc-pop-btn-customize'><a id='btnUpdate_" + deals.ID + "_" + deals.SubID + "_" + type + "_" + deals.MinSale + "_" + deals.MaxSale + "' class='cc-pop-btn'><i class='cc-pop-btn-txt'></i></a></p>  ";

//        }
//        else if (type == 3)//chon item
//        {
//            var len = deals.subItem.length;
//            var w = len * 241;
//            var quantity = 0;
//            classPopUp = "cc-nhienit cc-select-option";
//            html = "<p class='cc-pop-name'>" + deals.Name + "</p>" +
//            "<p>" + deals.Content + "</p>" +
//            "<div id='gallery_container' class='cc-pop-content cc-pop-slideshow'>" +
//            "<span id='spnPre' class='cc-pop-padding cc-pop-pre'></span>" +
//            "<span id='spnNext' class='cc-pop-padding cc-pop-next'></span>" +
//                "<div class='thumb_container'>" +
//        	    "<ul id='ulListPro' class='cc-pop-listpro' style='width:" + w + "px;'>";
//            for (var i = 0; i < deals.subItem.length; i++) {
//                quantity = (deals.subItem[i].Quantity > 0) ? deals.subItem[i].Quantity : 1;

//                html += "<li id='item_" + deals.subItem[i].SubID + "' class='cc-pop-pro thumbnail'>";
//                if (i < deals.subItem.length - 1) html += "<i class='cc-line-ver'></i>";
//                html += "<div class='cc-pop-pro-img'>" +
//                    	    "<img src='" + deals.subItem[i].Picture + "' alt='" + deals.subItem[i].NameColor + "' width='218' height='138'/>" +
//                            "<div class='cc-pop-pro-price'><span>" + formatMoney(deals.subItem[i].PriceSale, "", ",", "") + "<i>đ</i></span><em style='display:none'>" + deals.subItem[i].PriceSale + "</em></div>" +
//                        "</div>" +
//                        "<p class='cc-pop-pro-color'>" + sublen(deals.subItem[i].NameColor, 32) + "</p>" +
//                        "<div class='cc-pop-pro-info'>" +
//                    	    "<span class='cc-pop-check " + (parseInt(deals.subItem[i].Quantity) > 0 ? "cc-pop-checked" : "") + "'></span>" +
//                            "<div class='cc-pop-order'>                       " +
//                                "<span class='cc-pop-order-txt'>" + lang[3] + "</span>" +
//                                "<div class='cc-select'>" +
//                                        "<select class='cc-pop-selectbox'>";


//                for (var j = deals.MinSale; j <= deals.MaxSale; j++) {
//                    html += "<option value='" + j + "' " + (quantity == j ? "selected='selected'" : "") + "  >" + j + "</option>";
//                }
//                html += "</select>" +

//                                "</div>" +
//                    	    "</div> " +
//                        "</div>" +
//                    "</li>";
//            }
//            html += "</ul>" +
//            "</div>" +
//            "</div>" +
//            "<p class='cc-pop-btn-customize'><a id='btnUpdate_" + deals.ID + "_" + deals.SubID + "_" + type + "_" + deals.MinSale + "_" + deals.MaxSale + "' class='cc-pop-btn'><i class='cc-pop-btn-txt'></i></a><i class='cc-pop-line top'></i></p>  ";
//        }
//        else if (type == 4) { //giay chung nhan
//            classPopUp = "cc-nhienit";
//            html = "<p class='cc-pop-name'>" + deals.Name + "</p>" +
//                "<p>" + new langTitlePopUp()[1] + "</p>" +
//                "<div class='cc-pop-img'>" +
//        	         "<img src='" + deals.PicVoucher + "' alt='" + deals.Name + "' width='405' height='479'/>" +
//                "</div>" +
//                "<div class='cc-pop-order'>" +
//        	        "<i class='cc-pop-line top'></i>" +
//                    "<span class='cc-pop-order-txt'>" + lang[0] + ":</span>" +
//                    "<div class='cc-select'>" +
//            	        "<div class='cc-selected'><span>" + deals.Quantity + "</span><i></i></div>" +
//                        "<div class='cc-list-select' style='display:none;'>" +
//                           "<ul>";
//            for (var i = deals.MinSale; i <= deals.MaxSale; i++) {
//                html += "<li>" + i + "</li>";
//            }
//            html += "</ul>" +
//                        "</div>" +
//                    "</div>" +
//                    "<i class='cc-pop-line bottom'></i>" +
//                "</div>  " +
//                "<p class='cc-pop-btn-customize'><a id='btnUpdate_" + deals.ID + "_" + deals.SubID + "_" + type + "_" + deals.MinSale + "_" + deals.MaxSale + "' class='cc-pop-btn'><i class='cc-pop-btn-txt'></i></a></p>";
//        }
//        else if (type == 5)//voucher
//        {
//            classPopUp = "cc-nhienit";
//            html += "<p class='cc-pop-name'>" + deals.Name + "</p>" +
//            "<p>" + new langTitlePopUp()[0] + "</p>" +
//            "<div class='cc-pop-img'>" +
//        	     "<img src='" + deals.PicVoucher + "' alt='" + deals.Name + "' width='405' height='244'/>" +
//            "</div>" +
//            "<div class='cc-pop-order'>" +
//        	    "<i class='cc-pop-line top'></i>" +
//                "<span class='cc-pop-order-txt'>" + lang[0] + ":</span>" +
//                "<div class='cc-select'>" +
//            	    "<div class='cc-selected'><span>" + deals.Quantity + "</span><i></i></div>" +
//                    "<div class='cc-list-select' style='display:none;'>" +
//                         "<ul>";
//            for (var i = deals.MinSale; i <= deals.MaxSale; i++) {
//                html += "<li>" + i + "</li>";
//            }
//            html += "</ul>" +
//                    "</div>" +
//                "</div>" +
//                "<i class='cc-pop-line bottom'></i>" +
//            "</div>  " +
//            "<p class='cc-pop-btn-customize'><a id='btnUpdate_" + deals.ID + "_" + deals.SubID + "_" + type + "_" + deals.MinSale + "_" + deals.MaxSale + "' class='cc-pop-btn'><i class='cc-pop-btn-txt'></i></a></p>";
//        }
//        //show popup
//        var divPopUp = $("divPoupCart");
//        divPopUp.className = "ccart-popup " + classPopUp;
//        $("divPoupCartContent").innerHTML = html;
//        //        setPopUpCenter("divPoupCart");
//        //        //$j('body,html').css({"overflow":"hidden"});
//        //        $j("#dShadow").fadeIn(500, function() {
//        //            $j('#divPoupCart').fadeIn(500);
//        //            $j('#divPoupCart .ccart-pop-close').click(function() {
//        //                $j('#divPoupCart').fadeOut(500, function() {
//        //                    //$j('body,html').css({ "overflow": "auto" });             
//        //                    $j("#dShadow").fadeOut(500);
//        //                });
//        //            });
//        //        });
//        copyPosition(true, null, divPopUp, 0, 0);
//        $("dShadow").show();
//        new Effect.Appear(divPopUp, 0, 1);
//        divPopUp.down('.ccart-pop-close').observe('click', function() {//close pop up
//            new Effect.Fade(divPopUp, 0.5, 0);
//            new Effect.Fade($("dShadow"), 0.5, 0);
//        });
//        try {
//            divPopUp.observe('click', changeQuantity);
//            divPopUp.down('.cc-pop-btn').observe('click', updateCartItem);
//            divPopUp.select('.cc-pop-color').invoke('observe', 'click', checkOptionColor);
//            divPopUp.select('.cc-pop-size').invoke('observe', 'click', checkOptionSize);
//            divPopUp.select('.cc-pop-check').invoke('observe', 'click', checkOptionItem);
//        } catch (ex) { };

//        if ($("gallery_container") != null) {
//            finishMoveGallery();
//            [$('spnNext'), $('spnPre')].invoke('observe', 'click', clickGallery);
//        }
//        //set size, color
//        try {
//            if (ageIDAct != 0) {
//                divPopUp.select(".color_" + ageIDAct + "").each(function(s) { s.show(); });
//                if (colorIDAct != 0) {
//                    divPopUp.select(".size_" + ageIDAct + "_" + colorIDAct + "").each(function(s) { s.show(); });
//                }
//                else
//                    divPopUp.select(".size_" + colorIDAct + "").each(function(s) { s.show(); });
//            }
//            else {
//                if (colorIDAct != 0) {
//                    divPopUp.select(".color_" + colorIDAct + "").each(function(s) { s.addClassName('active'); });
//                    divPopUp.down('.cc-pop-color').select('li').each(function(s) { s.show(); });
//                    divPopUp.select(".size_" + colorIDAct + "").each(function(s) { s.show(); });
//                }
//                else {
//                    if ($("divSize") != null) { $("divSize").select('li').each(function(s) { s.show(); }); }
//                }
//            }
//            //Thao 25.08
//            if (typeof (divPopUp.down('.cc-pop-color')) == "object" && divPopUp.down('.cc-pop-color').select('li').length <= 1) {
//                divPopUp.down('.cc-pop-color').style.display = "none";
//            }
//            if (typeof (divPopUp.down('.cc-pop-size')) == "object" && divPopUp.down('.cc-pop-size').select('li').length <= 1) {
//                divPopUp.down('.cc-pop-size').style.display = "none";
//            }
//        } catch (ef) { };
//    }
//};
/*funciton: event click check option item */
function checkOptionItem(e) {
    var ele = Event.element(e);
    if (ele.tagName != 'SPAN') return;
    if (ele.hasClassName("cc-pop-checked")) {
        ele.removeClassName('cc-pop-checked');
    }
    else {
        ele.addClassName('cc-pop-checked');
    }
};
/*function: event click color*/
function checkOptionColor(e) {
    var ele = Event.element(e);
    if (ele.tagName == 'IMG') ele = ele.up('a');
    if (ele.tagName != 'A') return;
    if (ele.hasClassName('active')) {
        ele.removeClassName('active');
    }
    else {
        var colorID = ele.id.split("_")[2];
        ele.up('ul').select('.color').each(function(s) { s.removeClassName('active'); });
        ele.addClassName('active');
        var ageID = ele.id.split("_")[3];
        var className = "size" + ((ageID != 0) ? ("_" + ageID) : "") + "_" + colorID;
        if ($("divSize") != null) {
            $("divSize").select('li').each(function(s) { s.hide(); });
            $("divSize").select("." + className + "").each(function(s) { s.show(); });


        }
        //$("imgKay").src = ele.next('span').innerHTML;
        //Thao 25.08
        var img = ele.next('span').innerHTML;
        if (img != "")
            $("imgKay").src = img;
    }
};
/*function: event click size*/
function checkOptionSize(e) {
    var ele = Event.element(e);
    if (ele.tagName == 'IMG') ele = ele.up('a');
    if (ele.tagName != 'A') return;
    if (ele.hasClassName('active')) {
        ele.removeClassName('active');
    }
    else {
        ele.up('ul').select('.active').each(function(s) { s.removeClassName('active'); });
        ele.addClassName('active');
        //$("imgKay").src = ele.next('span').innerHTML;
        //Thao 25.08
        var img = ele.next('span').innerHTML;
        if (img != "")
            $("imgKay").src = img;
    }
};
/*function: event onchange dropdownlist quantity on popup*/
function changeQuantity(e) {
    var ele = Event.element(e);
    $("divPoupCart").select('.cc-list-select').each(function(s) { if (s.style.display == "block") s.style.display = "none"; });
    if (ele.tagName == 'SPAN' || ele.tagName == 'I') ele = ele.up('div');
    if (typeof (ele) != "undefined" && ele.hasClassName('cc-selected')) {
        var listE = ele;
        var listEle = ele.next('.cc-list-select');
        listEle.style.display = (listEle.style.display == "none") ? "block" : "none";
        if (listEle.style.display == "block") {
            listEle.observe('click', function(s) {
                var eleS = Event.element(s);
                if (eleS.tagName.toUpperCase() == "LI") {
                    if (listE.down("span").innerHTML == eleS.innerHTML) return;
                    listE.down("span").innerHTML = eleS.innerHTML;
                    listEle.style.display = "none";
                    if ((eleS.id).indexOf('age') != -1) {
                        var ageID = eleS.id.split("_")[2];
                        var colorID = 0;
                        var objColor = $("divPoupCart").down(".cc-pop-color");
                        var objSize = $("divPoupCart").down(".cc-pop-size");
                        if (typeof (objColor) != undefined && objColor != null) {
                            objColor.select("li").each(function(s) { s.hide(); });
                            objColor.select(".color_" + ageID + "").each(function(s, index) {
                                s.show();
                                if (index == 0)
                                    colorID = s.down('a').id.split("_")[2];
                            });
                            if (typeof (objSize) != undefined && objSize != null) {
                                objSize.select("li").each(function(s) { s.hide(); });
                                var className = (colorID != 0) ? ("_" + colorID) : "";
                                objSize.select(".size_" + ageID + className + "").each(function(s) { s.show(); });
                            }
                        }
                        else {
                            if (typeof (objSize) != undefined && objSize != null) {
                                objSize.select("li").each(function(s) { s.hide(); });
                                objSize.select(".size_" + ageID + "").each(function(s) { s.show(); });
                            }
                        }
                    }
                }
            });
        }
    }
};
/*function: remove cart item*/
function removeCartItem(e) {
    var ele = Event.element(e);
    if (ele.tagName != 'A') return;
    var strID = ele.id.split("_");
    var id = strID[1];
    var subID = strID[2];
    paramRemoveCart.proID = id;
    paramRemoveCart.subID = subID;
    if ($('spAjaxLoader')) {
        $j('#spAjaxLoader').css({ "height": $j('.mod-descriptions').height() + "px" });
        $('spAjaxLoader').show();
    }
    var strUrlLocation = window.location.href;
    strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
    var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
    if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
        strUrlLink = strPathLink_All + "yahoo/";
    }
    if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
        utils.call(strUrlLink + "nhommuav4/HandlerRq.aspx", paramRemoveCart, "POST", "resultRemoveItem", "resultRemoveItem");
    }
    else {
        utils.call(strUrlLink + strStateNM + "/nhommuav4/HandlerRq.aspx", paramRemoveCart, "POST", "resultRemoveItem", "resultRemoveItem");
        //utils.call("http://localhost:50606/NhomMuaV4/HandlerRq.aspx", paramRemoveCart, "POST", "resultRemoveItem", "resultRemoveItem");
    }
};
/*function: ket qua tra ve khi xu ly remove cart item*/
function resultRemoveItem(str) {
    if ($('spAjaxLoader')) {
        $('spAjaxLoader').hide();
    }
    var isReloadCart = false;
    if (str == "1") {
        var objBtnRemove = $("btnRemove_" + paramRemoveCart.proID + "_" + paramRemoveCart.subID + "");
        if (objBtnRemove != null) {
            if ($j('#tblContent tr.tr_1').length == 1 && $j('#tblContent tr.tr_2').length == 0 && $j('#tblContent tr.tr_3').length == 0) {
                isReloadCart = true;
            }
            else if ($j('#tblContent tr.tr_1').length == 0 && $j('#tblContent tr.tr_2').length == 1 && $j('#tblContent tr.tr_3').length == 0) {
                isReloadCart = true;
            }
            else if ($j('#tblContent tr.tr_1').length == 0 && $j('#tblContent tr.tr_2').length == 0 && $j('#tblContent tr.tr_3').length == 1) {
                isReloadCart = true;
            }
            var objPriceItem = objBtnRemove.up('td').previous().down('span');
            var type = objPriceItem.id.split("_")[2];
            var priceItem = parseFloat(objPriceItem.next().innerHTML);
            var totalPrice = parseFloat($("spnTotalPrice_" + type + "").next().innerHTML);
            var totalAmountPrice = parseFloat($("spnTotalPrice").next().innerHTML);
            var totalPriceWeb = totalPrice - priceItem;
            $("spnTotalPrice_" + type + "").innerHTML = formatMoney(totalPriceWeb, "", ",", "") + "<i>đ</i>";
            $("spnTotalPrice_" + type + "").next().innerHTML = totalPriceWeb;
            //tinh tong so tien can thanh toan
            var totalNM = ($("spnTotalPrice_1") != null) ? parseFloat($("spnTotalPrice_1").next().innerHTML) : 0;
            var totalZap = ($("spnTotalPrice_2") != null) ? parseFloat($("spnTotalPrice_2").next().innerHTML) : 0;
            var totalKay = ($("spnTotalPrice_3") != null) ? parseFloat($("spnTotalPrice_3").next().innerHTML) : 0;
            var accountNM = ($("spnAccount_1") != null && $("iCheck_1") != null && $("iCheck_1").hasClassName('cc-checked') == true) ? parseFloat($('spnAccount_1').next().innerHTML) : 0;
            var accountZap = ($("spnAccount_2") != null && $("iCheck_2") != null && $("iCheck_2").hasClassName('cc-checked') == true) ? parseFloat($('spnAccount_2').next().innerHTML) : 0;
            var accountKay = ($("spnAccount_3") != null && $("iCheck_3") != null && $("iCheck_3").hasClassName('cc-checked') == true) ? parseFloat($('spnAccount_3').next().innerHTML) : 0;
            if ($("iCheck_" + type) != null && $("iCheck_" + type).hasClassName('cc-checked')) {
                var acc = parseFloat(($("spnAccount_" + type + "").next().innerHTML))
                if (totalPriceWeb > acc)
                    $("spnAccount_" + type + "").innerHTML = "-" + 0 + "<i>đ</i>";
                else
                    $("spnAccount_" + type + "").innerHTML = "-" + formatMoney(acc - totalPriceWeb, "", ",", "") + "<i>đ</i>";
            }
            totalNM = ((totalNM - accountNM) > 0) ? (totalNM - accountNM) : 0;
            totalKay = ((totalKay - accountKay) > 0) ? (totalKay - accountKay) : 0;
            totalZap = ((totalZap - accountZap) > 0) ? (totalZap - accountZap) : 0;
            var total = totalNM + totalZap + totalKay;
            $("spnTotalPrice").innerHTML = formatMoney(total, "", ",", "") + "<i>đ</i>";
            $("spnTotalPrice").next().innerHTML = total;
            objBtnRemove.up('table').up('tr').remove();


            //set tong tien gio hang tren header
            var totalQuantity = 0;
            $("tblContent").select('.cc-selected').each(function(s) { totalQuantity += parseInt(s.down("span").innerHTML); });
            $("totalMoneyHeader").innerHTML = formatMoney(total, "", ",", "") + "<sup>đ</sup>";
            $("totalAmountHeader").innerHTML = totalQuantity;
        }
        if (isReloadCart == true) {
            window.location.reload();
        }
    }
    else {
        showMessage(new langCart()[4]);
    }
};
/*function: event click button update tren popup*/
function updateCartItem(e) {
    var lang = new langCart();
    var ele = Event.element(e);
    if (ele.tagName == 'I') ele = ele.up('a');
    var strID = ele.id.split("_");
    var proID = strID[1];
    var type = strID[3];
    var subID = strID[2];
    var minsale = parseInt(strID[4]);
    var maxsale = parseInt(strID[5]);
    var quantity = 0;
    var optionID = 0; //ID KayOption 
    var strOption = "";
    paramUpdateCart.tpPro = type;
    paramUpdateCart.proID = proID;
    paramUpdateCart.subID = subID;
    if (type == 1 || type == 2 || type == 4 || type == 5) {//san pham, luxury, voucher, giay chung nhan
        var objBtn = ele.up('.cc-pop-btn-customize');
        var ojbQuantity = objBtn.previous().down('.cc-selected').down('span');
        quantity = parseInt(ojbQuantity.innerHTML);
        paramUpdateCart.quantity = quantity;
    }
    if (type == 2) { //luxury
        var parent = objBtn.up('.cc-pop-content');
        var objColor = parent.down('.cc-pop-color');
        var objSize = parent.down('.cc-pop-size');
        var objAge = parent.down('.cc-selected');
        if (typeof (objColor) != "undefined" && objColor != null && typeof (objSize) != "undefined" && objSize != null) {
            var objAcSize = objSize.select('.active');
            if (typeof (objAcSize) != "undefined" && objAcSize.length > 0) {
                optionID = objAcSize[0].id.split("_")[1];
                paramUpdateCart.optionID = optionID;
                paramUpdateCart.optionName = lang[8] + " " + objAcSize[0].innerHTML;
            }
        }
        else if (typeof (objSize) != "undefined" && objSize != null) {
            var objAcSize = objSize.select('.active');
            if (typeof (objAcSize) != "undefined" && objAcSize.length > 0) {
                optionID = objAcSize[0].id.split("_")[1];
                paramUpdateCart.optionID = optionID;
                paramUpdateCart.optionName = lang[8] + " " + objAcSize[0].innerHTML;
            }
        }
        else if (typeof (objColor) != "undefined" && objColor != null) {
            var objAcColor = objColor.select('.active');
            if (typeof (objAcColor) != "undefined" && objAcColor.length > 0) {
                optionID = objAcColor[0].id.split("_")[1];
                paramUpdateCart.optionID = optionID;
                paramUpdateCart.optionName = lang[15] + " " + objAcColor[0].name;
            }
        } else { //age
            if (typeof (objAge) != "undefined" && objAge != null) {
                var ageName = $("spanAge").innerHTML;

                objAge.next().select("li").each(function(s) {
                    if (s.innerHTML == ageName) {
                        paramUpdateCart.optionID = s.id.split("_")[1];
                        paramUpdateCart.optionName = lang[18] + " " + ageName;
                    }
                });
            }
        }
    }
    if (type == 3) { //deal option
        if ($("ulListPro") != null) {
            $("ulListPro").select('.cc-pop-pro').each(function(s) {
                var optionID = s.id.split("_")[1];
                var optionQuantity = 0;
                if (s.down('.cc-pop-check').hasClassName('cc-pop-checked')) {
                    optionQuantity = s.down('.cc-pop-selectbox').value;
                    quantity += parseInt(optionQuantity);
                }
                strOption += optionID + "_" + optionQuantity + "#";
            });
        }
        paramUpdateCart.subID = 0;
        strOption = (strOption != "") ? strOption.substring(0, strOption.length - 1) : strOption;
        paramUpdateCart.strOption = strOption;
    }
    if (quantity >= minsale && quantity <= maxsale) {
        var strUrlLocation = window.location.href;
        strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
        var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
        if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
            strUrlLink = strPathLink_All + "yahoo/";
        }
        if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
            utils.call(strUrlLink + "nhommuav4/HandlerRq.aspx", paramUpdateCart, "POST", "resultUpdateItem", "resultUpdateItem");
        }
        else {
            utils.call(strUrlLink + strStateNM + "/nhommuav4/HandlerRq.aspx", paramUpdateCart, "POST", "resultUpdateItem", "resultUpdateItem");
            //utils.call("http://localhost:50606/NhomMuaV4/HandlerRq.aspx", paramUpdateCart, "POST", "resultUpdateItem", "resultUpdateItem");
        }
    }
    else {
        //new Effect.Fade($("divPoupCart"), 0.5, 0);
        showMessage(new langCart()[16].replace("##minsale##", minsale).replace("##maxsale##", maxsale));
    }
};
/*function: ket qua tra ve khi update*/
function resultUpdateItem(str) {
    if ($('spAjaxLoader')) {
        $('spAjaxLoader').hide();
    }
    if (str == "1") {
        //update lai table
        if (paramUpdateCart.tpPro == 3)//chon item
        {
            //new Effect.Fade($("divPoupCart"), 0.5, 0);
            //new Effect.Fade($("dShadow"), 0.5, 0);
            $j("#divPoupCart").slideUp(500,function(){
                $j("#dShadow").fadeOut(500);
            });
            window.location.reload();
        }
        else {
            /*if (paramUpdateCart.tpPro == 2 && $("pro_" + paramUpdateCart.proID + "_" + paramUpdateCart.tpPro) != null) {
            try {
            $("pro_" + paramUpdateCart.proID + "_" + paramUpdateCart.tpPro).innerHTML = paramUpdateCart.optionName;
            } catch (f) { };
            }*/
            var objQuantity = $("spnQuantity_" + paramUpdateCart.proID + "_" + paramUpdateCart.subID + "");
            objQuantity.innerHTML = paramUpdateCart.quantity;
            var objPrice = objQuantity.up('td').next(0).down("span");
            var objTotalPrice = objQuantity.up('td').next(1).down("span");
            var type = objTotalPrice.id.split("_")[2];

            var price = parseFloat(objPrice.next().innerHTML);
            var totalPrice = parseFloat(objTotalPrice.next().innerHTML);
            var subPrice = (parseInt(paramUpdateCart.quantity) * price) - totalPrice;
            //gan tong tien cua item can thanh toan
            objTotalPrice.innerHTML = formatMoney(parseInt(paramUpdateCart.quantity) * price, "", ",", "") + "<i>đ</i>";
            objTotalPrice.next().innerHTML = parseInt(paramUpdateCart.quantity) * price;
            //gan tong so tien thanh toan cua tai khoan
            var totalPriceWeb = parseFloat($("spnTotalPrice_" + type).next().innerHTML) + subPrice;
            var totalAmountPrice = parseFloat($("spnTotalPrice").next().innerHTML) + subPrice;
            $("spnTotalPrice_" + type).innerHTML = formatMoney(totalPriceWeb, "", ",", "") + "<i>đ</i>";
            $("spnTotalPrice_" + type).next().innerHTML = totalPriceWeb;

            //tinh tong so tien can thanh toan
            var totalNM = ($("spnTotalPrice_1") != null) ? parseFloat($("spnTotalPrice_1").next().innerHTML) : 0;
            var totalZap = ($("spnTotalPrice_2") != null) ? parseFloat($("spnTotalPrice_2").next().innerHTML) : 0;
            var totalKay = ($("spnTotalPrice_3") != null) ? parseFloat($("spnTotalPrice_3").next().innerHTML) : 0;
            var accountNM = ($("spnAccount_1") != null && $("iCheck_1") != null && $("iCheck_1").hasClassName('cc-checked') == true) ? parseFloat($('spnAccount_1').next().innerHTML) : 0;
            var accountZap = ($("spnAccount_2") != null && $("iCheck_2") != null && $("iCheck_2").hasClassName('cc-checked') == true) ? parseFloat($('spnAccount_2').next().innerHTML) : 0;
            var accountKay = ($("spnAccount_3") != null && $("iCheck_3") != null && $("iCheck_3").hasClassName('cc-checked') == true) ? parseFloat($('spnAccount_3').next().innerHTML) : 0;
            if ($("iCheck_" + type) != null && $("iCheck_" + type).hasClassName('cc-checked')) {
                var acc = parseFloat(($("spnAccount_" + type + "").next().innerHTML))
                if (totalPriceWeb > acc)
                    $("spnAccount_" + type + "").innerHTML = "-" + 0 + "<i>đ</i>";
                else
                    $("spnAccount_" + type + "").innerHTML = "-" + formatMoney(acc - totalPriceWeb, "", ",", "") + "<i>đ</i>";
            }
            totalNM = ((totalNM - accountNM) > 0) ? (totalNM - accountNM) : 0;
            totalKay = ((totalKay - accountKay) > 0) ? (totalKay - accountKay) : 0;
            totalZap = ((totalZap - accountZap) > 0) ? (totalZap - accountZap) : 0;
            var total = totalNM + totalZap + totalKay;
            $("spnTotalPrice").innerHTML = formatMoney(total, "", ",", "") + "<i>đ</i>";
            $("spnTotalPrice").next().innerHTML = total;
            //end

            //set tong tien gio hang tren header //Thao 27.7
            var totalQuantity = 0;
            $("tblContent").select('.cc-selected').each(function(s) { totalQuantity += parseInt(s.down("span").innerHTML); });
            $("totalMoneyHeader").innerHTML = formatMoney(total, "", ",", "") + "<sup>đ</sup>";
            $("totalAmountHeader").innerHTML = totalQuantity;

            /*new Effect.Fade($("divPoupCart"), 0.5, 0);
            new Effect.Fade($("dShadow"), 0.5, 0);*/
            $j("#divPoupCart").slideUp(500,function(){
                $j("#dShadow").fadeOut(500);
            });
        }
    }
    else {
        //new Effect.Fade($("divPoupCart"), 0.5, 0);
        showMessage(new langCart()[5]);
        //alert(new langCart()[5]);
    }
};
/*event click button next, previous of gallery item option*/
function clickGallery(e) {
    var ele = Event.element(e);
    if (ele.tagName != 'SPAN') return;
    var thumb = $("ulListPro");
    var item = thumb.down('li');
    var wItem = item.getWidth();
    var w = wItem * row;
    if (ele.hasClassName('active')) {
        if (ele.hasClassName('cc-pop-pre')) {
            ele.stopObserving('click', clickGallery);
            new Effect.Move(thumb, { x: w, y: 0, mode: 'relative', duration: 1, afterFinish: finishMoveGallery });
        }
        else if (ele.hasClassName('cc-pop-next')) {
            ele.stopObserving('click', clickGallery);
            new Effect.Move(thumb, { x: -w, y: 0, mode: 'relative', duration: 1, afterFinish: finishMoveGallery });
        }
    }
};
/*function: xu ly sau khi di chuyen gallery xong*/
function finishMoveGallery() {
    var thumb = $("ulListPro");
    var lThumb = utils.rejectUnit(thumb.style.left);
    var wThumb = thumb.getWidth();
    var item = thumb.down('li');
    var wItem = item.getWidth() * row;
    if (lThumb == 0) $('spnPre').removeClassName('active');
    else if (lThumb < 0) $('spnPre').addClassName('active');
    if (thumb.select('li').length <= row) {
        $('spnPre').removeClassName('active');
        $('spnNext').removeClassName('active');
    }
    else if (Math.abs(lThumb) + wItem > wThumb) $('spnNext').removeClassName('active');
    else $('spnNext').addClassName('active');
    [$('spnNext'), $('spnPre')].invoke('observe', 'click', clickGallery);
};
/*function: update quantity of item on table*/
function resultUpdateOnTable(str) {
    if ($('spAjaxLoader')) {
        $('spAjaxLoader').hide();
    }
    if (str != "1") {
        showMessage(new langCart()[5]);
        ///alert(new langCart()[5]);
    }
};

/*function: show popup hoa don do*/
function showPopUpTax() {
    var lang = new langCart();
    var html = "";

    if (typeof (strTaxCode) != "undefined" && strTaxCode != "-1") {
        try { objTaxCode = strTaxCode.evalJSON(true); } catch (ex) { objTaxCode = strTaxCode; }
        html += "<p class='cc-pop-name'>" + lang[9] + "</p>" +
                "<div class='cc-pop-order' style='height:auto;'>" +
                 "<i class='cc-pop-line top'></i>" +
                    "<div class='pf-form'>" +
                        "<p class='row'>" +
                            "<input type='text' id='txtViewName' class='input focus' value='" + objTaxCode.NameTax + "'/>" +
                            "<label for='txtViewName' class='placeholder'>" + ((objTaxCode.NameTax == "") ? lang[10] : "") + "</label>" +
                            "<span id='spnErrorViewName' class='error'></span>" +
                        "</p>" +
                        "<p class='row'>" +
                            "<input type='text' id='txtViewAdd' class='input " + ((objTaxCode.AddTax == "") ? "" : "focus") + "' value='" + objTaxCode.AddTax + "'/>" +
                            "<label for='txtViewAdd' class='placeholder'>" + ((objTaxCode.AddTax == "") ? lang[11] : "") + "</label>" +
                            "<span id='spnErrorViewAdd' class='error'></span>" +
                        "</p>" +
                        "<p class='row'>" +
                            "<input type='text' id='txtViewTax' class='input " + ((objTaxCode.CodeTax == "") ? "" : "focus") + "' value='" + objTaxCode.CodeTax + "'/>" +
                            "<label for='txtViewTax' class='placeholder'>" + ((objTaxCode.CodeTax == "") ? lang[12] : "") + "</label>" +
                            "<span id='spnErrorViewTax' class='error'></span>" +
                        "</p>" +
                    "</div>" +
                    "<i class='cc-pop-line bottom'></i>" +
                "</div>" +
                "<p class='cc-pop-btn-customize'><a id='btnAcceptTax' class='cc-pop-btn'><i class='cc-pop-btn-txt btn-dongy'></i></a></p>";

        var divPopUp = $("divPoupCart");
        divPopUp.down('.ccart-popup-inner').innerHTML = html;
        divPopUp.className = "ccart-popup cc-zap";
        $("dShadow").show();
        copyPosition(true, null, divPopUp, 0, 0);
        new Effect.Appear(divPopUp, 0, 1);
        divPopUp.down('.ccart-pop-close').observe('click', function() {//close pop up
            new Effect.Fade(divPopUp, 0.5, 0);
            new Effect.Fade($("dShadow"), 0.5, 0);
        });
        loadTextboxEventCart(divPopUp);
        if ($("btnAcceptTax") != null) $("btnAcceptTax").observe('click', setInfoTax);
    }
};
/*
function: xu ly validation form 'xuat hoa don do'
*/
function checkVATBill() {
    var langVAT = langVATBill();
    var checkBill = true;
    if (utils.trim($("txtViewName").value) == "") {
        $("spnErrorViewName").update(langVAT[0]);
        checkBill = false;
    }
    else {
        $("spnErrorViewName").update("");
    }
    if (utils.trim($("txtViewAdd").value) == "") {
        $("spnErrorViewAdd").update(langVAT[1]);
        checkBill = false;
    }
    else {
        $("spnErrorViewAdd").update("");
    }
    if ($("txtViewTax").value == "") {
        $("spnErrorViewTax").update(langVAT[2]);
        checkBill = false;
    }
    else {
        var codeTax = utils.trim($("txtViewTax").value);
        if (codeTax == "") {
            $("spnErrorViewTax").update(langVAT[2]);
            checkBill = false;
        }
        else {
            if (utils.isNumeric(codeTax) == false) {
                $("spnErrorViewTax").update(langVAT[3]);
                checkBill = false;
            }
            else if (codeTax.length < 6 || codeTax.length > 20) {
                $("spnErrorViewTax").update(langVAT[4]);
                checkBill = false;
            }
            else {
                $("spnErrorViewTax").update("");
            }
        }
    }
    return checkBill;
};
/*funtion: xu ly update thong tin hoa don do*/
function setInfoTax() {
    if (checkVATBill() == true) {
        paramAcceptTax.name = $("txtViewName").value;
        paramAcceptTax.address = $("txtViewAdd").value;
        paramAcceptTax.codetax = $("txtViewTax").value;
        paramAcceptTax.isTaxCode = true;
        if ($('spAjaxLoader')) {
            $j('#spAjaxLoader').css({ "height": $j('.mod-descriptions').height() + "px" });
            $('spAjaxLoader').show();
        }
        var strUrlLocation = window.location.href;
        strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
        var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
        if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
            strUrlLink = strPathLink_All + "yahoo/";
        }
        if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
            utils.call(strUrlLink + "nhommuav4/HandlerRq.aspx", paramAcceptTax, "POST", "resultSetInfoTax", "resultSetInfoTax");
        }
        else {
            utils.call(strUrlLink + strStateNM + "/nhommuav4/HandlerRq.aspx", paramAcceptTax, "POST", "resultSetInfoTax", "resultSetInfoTax");
            //utils.call("http://localhost:50606/NhomMuaV4/HandlerRq.aspx", paramAcceptTax, "POST", "resultSetInfoTax", "resultSetInfoTax");
        }
    }
};
/*function: ket qua tra ve khi update thong tin hoa don do*/
function resultSetInfoTax(str) {
    if ($('spAjaxLoader')) {
        $('spAjaxLoader').hide();
    }
    if (str.toLowerCase() == "true") {  //thuc hien thanh cong
        if (objTaxCode != null) {
            objTaxCode.NameTax = paramAcceptTax.name;
            objTaxCode.AddTax = paramAcceptTax.address;
            objTaxCode.CodeTax = paramAcceptTax.codetax;
            objTaxCode.isCodeTax = paramAcceptTax.isTaxCode;
        }
        if ($("btnEditTax") != null && $("btnEditTax").style.display == "none") {
            $("btnEditTax").style.display = "block";
        }
        new Effect.Fade($("divPoupCart"), 0.5, 0);
        new Effect.Fade($("dShadow"), 0.5, 0);
    }
};
/*function: ket qua tra ve khi remove hoa don do*/
function resultRemoveTax(str) {
    if (str.toLowerCase() == "true") {
        if ($("btnEditTax") != null && $("btnEditTax").style.display == "block") {
            $("btnEditTax").style.display = "none";
        }
    }
};

function sublen(str, length) {
    return (str.length < length) ? str : str.substring(0, length - 3) + "...";
};


function copyPosition(isCenter, ele_source, ele_copy, top, left) {
    try {
        if (isCenter) {
            var wh_copy = ele_copy.getDimensions();
            var w_moniter = utils.windowSize();
            var scrollOff = document.viewport.getScrollOffsets()[1];
            if (isNaN(scrollOff))
                scrollOff = 0;
            var newT = Math.ceil(((w_moniter[1] - wh_copy.height) / 2 + scrollOff + top));
            var newL = Math.ceil(((w_moniter[0] - wh_copy.width) / 2 + left));
            if (newT < 0) newT = 0;
            if (newL < 0) newL = 0;
            ele_copy.style.top = newT + 'px';
            ele_copy.style.left = newL + 'px';
        }
        else {
            var arrPos = ele_source.cumulativeOffset();
            ele_copy.style.top = Math.ceil((arrPos[1] + top)) + 'px';
            ele_copy.style.left = Math.ceil((arrPos[0] + left)) + 'px';
            if (!ele_copy.name || ele_copy.name == "")
                ele_copy.name = ele_source.id;
        }
    } catch (ex) { };
};
function showMessage(str) {
    var html = "<div class='p-bg p-title'><h2>Thông Báo</h2></div>";
    html += "<div class='p-container'><div class='p-form'><p class='row'><span class='message'>" + str + "</span></p></div></div>";
    var divPopUp = $("divPoupCart");
    divPopUp.down('.ccart-popup-inner').innerHTML = html;
    divPopUp.className = "ccart-popup cc-message";
    $("dShadow").show();
    copyPosition(true, null, divPopUp, 0, 0);
    new Effect.Appear(divPopUp, 0, 1);
    divPopUp.down('.ccart-pop-close').observe('click', function() {//close pop up
        new Effect.Fade(divPopUp, 0.5, 0);
        new Effect.Fade($("dShadow"), 0.5, 0);
    });
};
/*
Load events for textbox
*/
function loadTextboxEventCart(container) {
    var arr = container.select('.input,.textarea');
    arr.invoke('observe', 'click', textboxFocusCart);
    arr.invoke('observe', 'focus', textboxFocusCart);
    arr.invoke('observe', 'blur', textboxBlurCart);
    arr.invoke('observe', 'keyup', textboxFocusCart);
};

function textboxFocusCart(e) {
    var ele = Event.element(e);
    var el = ele.up();
    var label = el.down('label');
    if (ele.value == '') {
        label.show();
    } else {
        label.hide();
    }
    if (!ele.hasClassName('focus')) {
        ele.addClassName('focus');
    }
};
function textboxBlurCart(e) {
    var ele = Event.element(e);
    var el = ele.up();
    var label = el.down('label');
    if (ele.value == '') {
        label.show();
        if (ele.hasClassName('focus')) {
            ele.removeClassName('focus');
        }
    } else {
        label.hide();
        if (!ele.hasClassName('focus')) {
            ele.addClassName('focus');
        }
    }
    validBlurCart(ele.id);
};

//function: validation register member
function validBlurCart(id) {
    var langVAT = langVATBill();
    switch (id) {
        //payment vat               
        case "txtViewName":
            if (utils.trim($("txtViewName").value) == "") {
                $("spnErrorViewName").update(langVAT[0]);
            }
            else {
                $("spnErrorViewName").update("");
            }
            break;
        case "txtViewAdd":
            if (utils.trim($("txtViewAdd").value) == "") {
                $("spnErrorViewAdd").update(langVAT[1]);
            }
            else {
                $("spnErrorViewAdd").update("");
            }
            break;
        case "txtViewTax":
            var codeTax = utils.trim($("txtViewTax").value);
            if (codeTax == "") {
                $("spnErrorViewTax").update(langVAT[2]);
            }
            else {
                if (utils.isNumeric(codeTax) == false) {

                    $("spnErrorViewTax").update(langVAT[3]);
                }
                else if (codeTax.length < 6 || codeTax.length > 20) {
                    $("spnErrorViewTax").update(langVAT[4]);
                }
                else {
                    $("spnErrorViewTax").update("");
                }
            }
            break;
    }
};
//function: validation register member
function valiBlur(id) {
    var langN = new langRegistry();
    if (id == 'txtRegName') {
        if (utils.trim($('txtRegName').value) == "") {
            $('spnRegName').update(new langRegistry()[17]); return false;
        }
        else { $('spnRegName').update(""); }
    }
    if (id == 'txtRegEmail') {
        if (utils.trim($('txtRegEmail').value) == "") { $('spnRegEmail').update(langN[0]); return false; }
        else {
            checkEmailExist();
        }
    }
    if (id == 'txtRegNickName') {
        if (utils.trim($('txtRegNickName').value) == "") { $('spnRegNickName').update(langN[23]); return false; }
        var chkNick = valiNickName($('txtRegNickName').value, $('spnRegNickName'));
        if (chkNick == false) return false;
    }
    if (id == 'txtRegPass') {
        var strMsg1 = checkValidatePass($('txtRegPass').value);
        if (strMsg1 != "") {
            $('spnRegPass').update(strMsg1);
            return false;
        }
        else {
            $('spnRegPass').update("");
            if ($('txtRegPassRe').value != "") {
                if ($('txtRegPass').value != $('txtRegPassRe').value) { $('spnRegPassRe').update(langN[5]); return false; }
                else { $('spnRegPassRe').update(""); }
            }
        }
    }
    if (id == 'txtRegPassRe') {
        var strMsg2 = checkValidatePass($('txtRegPassRe').value);
        if (strMsg2 != "") {
            $('spnRegPassRe').update(strMsg2);
            return false;
        }
        if ($('txtRegPass').value != $('txtRegPassRe').value) { $('spnRegPassRe').update(langN[5]); return false; }
        else { $('spnRegPassRe').update(""); }
    }

    if (id == 'txtLogEmail') {
        if (utils.trim($('txtLogEmail').value) == "") { $('spnEmail').update(langN[0]); return false; }
        else {
            if (!checkMail(utils.trim($('txtLogEmail').value))) { $('spnEmail').update(langN[1]); return false; }
            else {
                $('spnEmail').update("");
            }
        }
    }
    if (id == 'txtLogPass') {
        var strMsg5 = checkValidatePass($('txtLogPass').value);
        if (strMsg5 != "") {
            $('spnPass').update(strMsg5);
            return false;
        }
        else $('spnPass').update("");
    }
    /*form viewcart*/
    if (id == 'txtViewEmail') {
        if (utils.trim($('txtViewEmail').value) == "") { $('spnViewEmail').update(langN[0]); return false; }
        else {
            if (!checkMail(utils.trim($('txtViewEmail').value))) { $('spnViewEmail').update(langN[1]); return false; }
            else {
                $('spnViewEmail').update("");
                checkViewAccountEmailExist();
            }
        }
    }
    if (id == 'txtViewPass') {
        var strMsg3 = checkValidatePass($('txtViewPass').value);
        if (strMsg3 != "") {
            $('spnViewPass').update(strMsg3);
            return false;
        }
        else {
            $('spnViewPass').update("");
            if ($('txtReViewPass').value != "") {
                if ($('txtViewPass').value != $('txtReViewPass').value) { $('spnReViewPass').update(langN[5]); return false; }
                else { $('spnReViewPass').update(""); }
            }
        }
    }
    if (id == 'txtReViewPass') {
        var strMsg4 = checkValidatePass($('txtReViewPass').value);
        if (strMsg4 != "") {
            $('spnReViewPass').update(strMsg4);
            return false;
        }
        if ($('txtReViewPass').value != $('txtViewPass').value) { $('spnReViewPass').update(langN[5]); return false; }
        else
            $('spnReViewPass').update("");
    }

    /* validate Capcha*/
    if (id == 'txt_captcha') {
        flagCaptcha = false;
        if ($('txt_captcha').value.length == 0) {
            $('spnCaptcha').update(new langRegistry()[16]);
            return false;
        }
        else {
            if (flagCaptcha == false) {
                var srcImg = $('imgCapcha').src;
                var guid = srcImg.split('?')[1].split("=")[1];
                var captcha = $('txt_captcha').value;
                if ($('spAjaxLoader')) {
                    $j('#spAjaxLoader').css({ "height": $j('.mod-descriptions').height() + "px" });
                    $('spAjaxLoader').show();
                }
                var strUrlLocation = window.location.href;
                strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
                var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
                if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
                    strUrlLink = strPathLink_All + "yahoo/";
                }
                if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
                    utils.call(strUrlLink + "HandlerRq.aspx", { 'stpe': 'capcha', 'capcha': captcha, 'guid': guid }, "POST", "checkValidateCode", "checkValidateCode");
                }
                else {
                    utils.call(strUrlLink + strStateNM + "/nhommuav4/HandlerRq.aspx", { 'stpe': 'capcha', 'capcha': captcha, 'guid': guid }, "POST", "checkValidateCode", "checkValidateCode");
                    //utils.call("http://localhost:50606/NhomMuaV4/HandlerRq.aspx", { 'stpe': 'capcha', 'capcha': captcha, 'guid': guid }, "POST", "checkValidateCode", "checkValidateCode");
                }
            }
        }
    }
    /*validate form Payment*/
    var lang = langErrorThanhToanHome();
    var langOffice = langErrorThanhToanOffice();
    var langVAT = langVATBill();
    switch (id) {
        case "txtHoTen_Home":
            if (utils.trim($("txtHoTen_Home").value) == "") {
                $('sMesE_HoTen_Home').innerHTML = lang[0];
                $('sMesE_HoTen_Home').style.display = '';
            }
            else {
                $('sMesE_HoTen_Home').innerHTML = "";
                $('sMesE_HoTen_Home').style.display = 'none';
            }
            break;
        case "txtTel_Home":
            var tel = utils.trim($("txtTel_Home").value);
            if (tel == "") {
                $('sMesE_Tel_Home').innerHTML = lang[1];
                $('sMesE_Tel_Home').style.display = '';
            } else if (!checkPhone(tel)) {
                $('sMesE_Tel_Home').innerHTML = lang[2];
                $('sMesE_Tel_Home').style.display = "";
            }
            else {
                $('sMesE_Tel_Home').innerHTML = "";
                $('sMesE_Tel_Home').style.display = 'none';
            }
            break;
        case "txtNum_Home":
            var numHome = utils.trim($('txtNum_Home').value);
            if (numHome == "") {
                if ($('sMesE_Street_Home').innerHTML == "") {
                    $('sMesE_Street_Home').innerHTML = lang[3];
                    $('sMesE_Street_Home').style.display = '';
                }
                else {
                    var streetHome = utils.trim($('txtStreet_Home').value);
                    if (streetHome == "") {
                        $('sMesE_Street_Home').innerHTML = lang[6];
                        $('sMesE_Street_Home').style.display = '';
                    }
                }
            }
            else {
                if ($('sMesE_Street_Home').innerHTML == "") {
                    $('sMesE_Street_Home').innerHTML = "";
                    $('sMesE_Street_Home').style.display = 'none';
                }
                else {
                    var streetHome = utils.trim($('txtStreet_Home').value);
                    if (streetHome == "") {
                        $('sMesE_Street_Home').innerHTML = lang[4];
                        $('sMesE_Street_Home').style.display = '';
                    }
                    else {
                        $('sMesE_Street_Home').innerHTML = "";
                        $('sMesE_Street_Home').style.display = '';
                    }
                }
            }
            break;
        case "txtStreet_Home":
            var numHome = utils.trim($('txtNum_Home').value);
            var streetHome = utils.trim($('txtStreet_Home').value);
            if (streetHome == "" && numHome != "") {
                $('sMesE_Street_Home').innerHTML = lang[4];
                $('sMesE_Street_Home').style.display = '';
            } else if (streetHome != "" && numHome == "") {
                $('sMesE_Street_Home').innerHTML = lang[3];
                $('sMesE_Street_Home').style.display = '';
            } else if (streetHome == "" && numHome == "") {
                $('sMesE_Street_Home').innerHTML = lang[6];
                $('sMesE_Street_Home').style.display = '';
            } else {
                $('sMesE_Street_Home').innerHTML = "";
                $('sMesE_Street_Home').style.display = 'none';
            }
            break;
        case "txtWard_Home":
            if (utils.trim($("txtWard_Home").value) == "") {
                $('sMesE_Ward_Home').innerHTML = lang[7];
                $('sMesE_Ward_Home').style.display = '';
            }
            else {
                $('sMesE_Ward_Home').innerHTML = "";
                $('sMesE_Ward_Home').style.display = 'none';
            }
            break;
        case "txtHoTen_Office":
            if (utils.trim($("txtHoTen_Office").value) == "") {
                $('sMesE_HoTen_Off').innerHTML = langOffice[0];
                $('sMesE_HoTen_Off').style.display = "";
            }
            else {
                $('sMesE_HoTen_Off').innerHTML = "";
                $('sMesE_HoTen_Off').style.display = "none";
            }
            break;
        case "txtTel_Office":
            var tel = utils.trim($("txtTel_Office").value);
            if (tel == "") {
                $('sMesE_Tel_Off').innerHTML = langOffice[1];
                $('sMesE_Tel_Off').style.display = "";
            } else if (!checkPhone(tel)) {
                check = false;
                $('sMesE_Tel_Off').innerHTML = langOffice[2];
                $('sMesE_Tel_Off').style.display = "";
            }
            else {
                $('sMesE_Tel_Off').innerHTML = "";
                $('sMesE_Tel_Off').style.display = "none";
            }
            break;
        //payment vat             
        case "txtViewName":
            if (utils.trim($("txtViewName").value) == "") {
                $("spnErrorViewName").update(langVAT[0]);
            }
            else {
                $("spnErrorViewName").update("");
            }
            break;
        case "txtViewAdd":
            if (utils.trim($("txtViewAdd").value) == "") {
                $("spnErrorViewAdd").update(langVAT[1]);
            }
            else {
                $("spnErrorViewAdd").update("");
            }
            break;
        case "txtViewTax":
            var codeTax = utils.trim($("txtViewTax").value);
            if (codeTax == "") {
                $("spnErrorViewTax").update(langVAT[2]);
            }
            else {
                if (utils.isNumeric(codeTax) == false) {

                    $("spnErrorViewTax").update(langVAT[3]);
                }
                else if (codeTax.length < 6 || codeTax.length > 20) {
                    $("spnErrorViewTax").update(langVAT[4]);
                }
                else {
                    $("spnErrorViewTax").update("");
                }
            }
            break;
        /*form forget pass*/ 
        case "txtForEmail":
            if (utils.trim($('txtForEmail').value) == "") { $('spnForEmail').update(langN[0]); flagForget = false; }
            else {
                if (checkMail(utils.trim($('txtForEmail').value))) {
                    if ($('spAjaxLoader')) {
                        $j('#spAjaxLoader').css({ "height": $j('.mod-descriptions').height() + "px" });
                        $('spAjaxLoader').show();
                    }
                    var strUrlLocation = window.location.href;
                    strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
                    var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
                    if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
                        strUrlLink = strPathLink_All + "yahoo/";
                    }
                    if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
                        utils.call(strUrlLink + "nhommuav4/HandlerRq.aspx", { 'stpe': 'checkEmailExist', 'email': $('txtForEmail').value }, "POST", "checkEmailForgetExistResult", "checkEmailForgetExistResult");
                    }
                    else {
                        utils.call(strUrlLink + strStateNM + "/nhommuav4/HandlerRq.aspx", { 'stpe': 'checkEmailExist', 'email': $('txtForEmail').value }, "POST", "checkEmailForgetExistResult", "checkEmailForgetExistResult");
                        //utils.call("http://localhost:50606/NhomMuaV4/HandlerRq.aspx", { 'stpe': 'checkEmailExist', 'email': $('txtForEmail').value }, "POST", "checkEmailForgetExistResult", "checkEmailForgetExistResult");
                    }
                }
                else {
                    $('spnForEmail').update(langN[1]);
                    flagForget = false;
                }
            }
    }
};